package database.utils;

import entity.Client;
import entity.UserConnectData;
import org.hibernate.cfg.Configuration;
import parsers.HibernateConfigurationParser;

import java.util.List;

/**
 * Created by alexander.makalov on 24.10.2014.
 */
public class HibernateConfig {
    private static Configuration configuration;

    public static Configuration getConfiguration(){
        if (configuration==null){
            configuration = new Configuration();
            HibernateConfigurationParser hibernateConfigurationParser = new HibernateConfigurationParser();
            hibernateConfigurationParser.startParsing();
        }
        return configuration;
    }

    public static void updateConfig(List<UserConnectData.SessionFactoryItem> sessionFactoryItems){
        getConfiguration();
        for (UserConnectData.SessionFactoryItem factoryItem : sessionFactoryItems){
            configuration.setProperty(factoryItem.getAttrbuteSring(),factoryItem.getValueString());
        }
        configuration.addAnnotatedClass(Client.class);

    }
}
